package com.pni.game.cards.components;

import java.util.ArrayList;
import java.util.Collection;

import com.pni.game.cards.Card;
import com.pni.game.cards.CardHolder;

/**
 * This class represents a player who sits at a table.  In typical card game, players are given cards, which are distributed
 * to them by the dealer.
 * @author Phil, Neil
 *
 */
public class Player implements CardHolder {

	private int seat;
	protected ArrayList<Card> cards;
	
	public Player(){
		seat = -1;
		this.cards = new ArrayList<Card>();
	}
	
	public void setSeatNumber(int seat){
		if(seat >= 0){
			this.seat = seat;
		}else{
			this.seat = -1;
		}
	}
	
	public int getSeatNumber(){
		return seat;
	}

	public void addCard(Card card) {
		cards.add(card);
	}

	public Card takeCard() {
		//we'll just take the first card from a hand on this call for now.
		if(cards.isEmpty()){
			return null;
		}
		Card card = cards.get(0);
		cards.remove(card);
		return card;
	}

	public Collection<Card> takeAllCards() {
		if(cards.isEmpty()){
			return null;
		}
		Collection<Card> cardsToReturn = cards.subList(0, cards.size());
		cards.removeAll(cardsToReturn);
		return cardsToReturn;
	}

	public Collection<Card> getCards() {
		return cards;
	}

	public int numberOfCards() {
		return cards.size();
	}

}
